package com.flute.framework.search;

import org.apache.lucene.search.payloads.PayloadFunction;

public class LayerPayLoadFunction extends PayloadFunction {

	private static final long serialVersionUID = 4696940053850855817L;

	@Override
	public float currentScore(int docId, String field, int start, int end,
			int numPayloadsSeen, float currentScore, float currentPayloadScore) {
		if (numPayloadsSeen == 0) {
			return currentPayloadScore;
		} else {
			return Math.max(currentPayloadScore, currentScore);
		}
	}

	@Override
	public float docScore(int docId, String field, int numPayloadsSeen,
			float payloadScore) {
		return numPayloadsSeen > 0 ? payloadScore : 1;
	}

	@Override
	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (o == null)
			return false;
		if (getClass() != o.getClass())
			return false;
		return true;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + this.getClass().hashCode();
		return result;
	}

}
